<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-4-7
 * Time: 上午9:59
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Balance_model extends MY_Model
{
    protected $table = 'balance_detail';
    //状态说明
    public function status_desc(&$data,$type=true) {
        //type : 1 赞赏支出 2 赞赏收入 3 悬赏发布押金 4 指派补差价 5 悬赏收入 6 悬赏全额退回 7 悬赏差价退回 8 提现 9 充值
        //status : 1 成功 2 冻结(发布需求完押金冻结) 3 申请中 4 失败 5 任务关闭已退回（悬赏支出）6 任务关闭退回（悬赏退回）
        //pay_ways : 1 微信 2 支付宝 3 余额
        if($type) {
            switch($data['type']) {
                case 1:
                    $data['type'] = '赞赏支出';
                    break;
                case 2:
                    $data['type'] = '赞赏收入';
                    break;
                case 3:
                    $data['type'] = '悬赏发布押金';
                    break;
                case 4:
                    $data['type'] = '指派补差价';
                    break;
                case 5:
                    $data['type'] = '悬赏收入';
                    break;
                case 6:
                    $data['type'] = '悬赏全额退回';
                    break;
                case 7:
                    $data['type'] = '悬赏差价退回';
                    break;
                case 8:
                    $data['type'] = '提现';
                    break;
                case 9:
                    $data['type'] = '充值';
                    break;
            }
        }

        switch($data['status']) {
            case 1:
                $data['status'] = '成功';
                break;
            case 2:
                $data['status'] = '冻结';
                break;
            case 3:
                $data['status'] = '申请中';
                break;
            case 4:
                $data['status'] = '失败';
                break;
            case 5:
                $data['status'] = '任务关闭已退回';
                break;
            case 6:
                $data['status'] = '任务关闭退回';
                break;
        }
        switch($data['pay_ways']) {
            case 1:
                $data['pay_ways'] = '微信';
                break;
            case 2:
                $data['pay_ways'] = '支付宝';
                break;
            case 3:
                $data['pay_ways'] = '余额';
                break;
        }
        return $data;
    }
    public function get_count_all($where=FALSE,$table=FALSE,$join=false){
        if (!$table) {
            $table = $this->table;
        }

        $count = 0;
        if ($where === FALSE) {
            if($join && is_array($join)) {
                $count = $this->db->join($join[0],$join[1],$join[2])->count_all_results($table);
            } else {
                $count  = $this->db->count_all_results($table);
            }

        }else{
            if($join && is_array($join)) {

                $count  = $this->db->join($join[0],$join[1],$join[2])->where($where)->count_all_results($table);

            } else {
                //var_dump($this->db->last_query());die();
                $count  = $this->db->where($where)->count_all_results($table);
            }

        }
        return $count;
    }
}